﻿@using NetCoreCMS.Models;
@using NetCoreCMS.Common;
@inject NetCoreCMS.IServices.IUsersService _users;
@inject NetCoreCMS.IServices.IShop_categoryService _shop_category;
@{
    Layout = "~/Areas/admin/Views/Shared/_LayoutList.cshtml";
    ViewBag.Title = "商铺管理";
    List<Shop> list = ViewData["list"] as List<Shop>;
}
<script>
    //查询数据
    function search() {
        var text = $("#txtKeywords").val();
        var pageCount = $("#txtPageNum").val();
        var groupId = $("#ddlGroupId").val();
        document.location = "index?keywords=" + text + "&pagesize=" + pageCount + "&group_id=" + groupId;
    }

    //ExePostBack回调函数
    function __doPostBack(objId) {
        if (objId == "btnAudit") {
            submitAudit();
        }
        if (objId == "btnDelete") {
            submitDelete();
        }
        if (objId == "btnSupply") {
            submitSupply();
        }
        if (objId == "btnLock") {
            submitLock();
        }
    }

    //批量审核
    function submitAudit() {
        var text = $("#txtKeywords").val();
        var $row = $("#ltable tr:gt(0)");
        var json = { list: [] };
        $($row).each(function (i, item) {
            if ($(item).find("input:checkbox").prop("checked")) {
                var id = $(item).find("td:eq(0)").find("label:eq(0)").text();
                var obj = { id: id };
                json.list.push(obj);
            }
        });
        $.ajax({
            url: "SubmitAudit?keywords=" + text,
            type: "POST",
            dataType: "html",
            data: "json=" + JSON.stringify(json),
            success: function (data) {
                eval(data);
            },
            error: function () {
                alert("error");
            }
        });
    }

    //批量删除
    function submitDelete() {
        var text = $("#txtKeywords").val();
        var $row = $("#ltable tr:gt(0)");
        var json = { list: [] };
        $($row).each(function (i, item) {
            if ($(item).find("input:checkbox").prop("checked")) {
                var id = $(item).find("td:eq(0)").find("label:eq(0)").text();
                var obj = { id: id };
                json.list.push(obj);
            }
        });
        $.ajax({
            url: "SubmitDelete?keywords=" + text,
            type: "POST",
            dataType: "html",
            data: "json=" + JSON.stringify(json),
            success: function (data) {
                eval(data);
            },
            error: function () {
                alert("error");
            }
        });
    }
    function submitSupply() {
        var text = $("#txtKeywords").val();
        var $row = $("#ltable tr:gt(0)");
        var json = { list: [] };
        $($row).each(function (i, item) {
            if ($(item).find("input:checkbox").prop("checked")) {
                var id = $(item).find("td:eq(0)").find("label:eq(0)").text();
                var obj = { id: id };
                json.list.push(obj);
            }
        });
        $.ajax({
            url: "SubmitSupply?keywords=" + text,
            type: "POST",
            dataType: "html",
            data: "json=" + JSON.stringify(json),
            success: function (data) {
                eval(data);
            },
            error: function () {
                alert("error");
            }
        });
    }
    function submitLock() {
        var text = $("#txtKeywords").val();
        var $row = $("#ltable tr:gt(0)");
        var json = { list: [] };
        $($row).each(function (i, item) {
            if ($(item).find("input:checkbox").prop("checked")) {
                var id = $(item).find("td:eq(0)").find("label:eq(0)").text();
                var obj = { id: id };
                json.list.push(obj);
            }
        });
        $.ajax({
            url: "SubmitLock?keywords=" + text,
            type: "POST",
            dataType: "html",
            data: "json=" + JSON.stringify(json),
            success: function (data) {
                eval(data);
            },
            error: function () {
                alert("error");
            }
        });
    }
</script>
<form id="form1" method="post" action="#">
    <!--导航栏-->
    <div class="location">
        <a href="javascript:history.back(-1);" class="back"><i class="iconfont icon-up"></i><span>返回上一页</span></a>
        <a href="../center/index"><i class="iconfont icon-home"></i><span>首页</span></a>
        <i class="arrow iconfont icon-arrow-right"></i>
        <span>商铺管理</span>
        <i class="arrow iconfont icon-arrow-right"></i>
        <span>商铺列表</span>
    </div>
    <!--/导航栏-->
    <!--工具栏-->
    <div id="floatHead" class="toolbar-wrap">
        <div class="toolbar">
            <div class="box-wrap">
                <a class="menu-btn"><i class="iconfont icon-more"></i></a>
                <div class="l-list">
                    <ul class="icon-list">
                        <li><a href="../shop_edit/index?action=@CMSEnums.ActionEnum.Add"><i class="iconfont icon-close"></i><span>新增</span></a></li>
                        <li><a href="javascript:;" id="btnSupply" class="lock" onclick="ExePostBack('btnSupply','设置成供货商，是否继续？');"><i class="iconfont icon-survey"></i><span>供货</span></a></li>
                        <li><a href="javascript:;" id="btnLock" class="lock" onclick="ExePostBack('btnLock','锁定商户取消提现等消费功能，是否继续？');"><i class="iconfont icon-survey"></i><span>锁定</span></a></li>
                        <li><a href="javascript:;" id="btnDelete" onclick="ExePostBack('btnDelete');"><i class="iconfont icon-delete"></i><span>删除</span></a></li>
                    </ul>
                </div>
                <div class="r-list">
                    <input type="text" id="txtKeywords" class="keyword" value="@ViewBag.Keywores" />
                    <a href="javascript:search()" id="lbtnSearch" class="btn-search"><i class="iconfont icon-search"></i></a>
                </div>
            </div>
        </div>
    </div>
    <!--/工具栏-->
    <!--列表-->
    <div class="table-container">
        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="ltable" id="ltable">
            <tr>
                <th width="8%">选择</th>
                <th align="left">商铺名称</th>
                <th align="left" width="10%">分类</th>
                <th align="left" width="10%">电话</th>
                <th align="left" width="18%">地址</th>
                <th width="6%">余额</th>
                <th width="6%">折扣</th>
                <th width="6%">锁定</th>
                <th width="6%">供货</th>
            </tr>
            @foreach (Shop dr in list)
            {
                var user = _users.GetModel(dr.user_id);
                string shop_user_name = "未设置";
                if(user!=null)
                {
                    shop_user_name = user.user_name;
                }
                <tr>
                    <td align="center">
                        <span class="checkall" style="vertical-align:middle;">
                            <input type="checkbox" />
                        </span>
                        <label style="display:none">@dr.id</label>
                    </td>
                    <td>
                        <div class="user-box" style="padding-left:0;">
                            <h4><b><a href="../shop_edit/index?action=@CMSEnums.ActionEnum.Edit&id=@dr.id">@dr.shopname</a></b> (店主：@shop_user_name</h4>
                            <i>注册时间：@dr.add_time.ToString("yyyy-MM-dd hh:mm:sss")</i>
                        </div>
                    </td>
                    <td>@_shop_category.GetModel(dr.category_id).title</td>
                    <td>@dr.mobile</td>
                    <td>@dr.area@dr.address</td>
                    <td align="center">@dr.point</td>
                    <td align="center">@dr.zhekou</td>
                    <td align="center">@Html.Raw((dr.is_lock))</td>
                    <td align="center">@Html.Raw((dr.is_supply))</td>
                </tr>
            }
            @if (list.Count == 0)
            {
                <tr><td align="center" colspan="9">暂无商铺</td></tr>
            }
        </table>

    </div>
    <!--/列表-->
    <!--内容底部-->
    <div class="line20"></div>
    <div class="pagelist">
        <div class="l-btns">
            <span>显示</span>
            <input type="text" id="txtPageNum" class="pagenum" value="@ViewBag.PageSize" onkeydown="return checkNumber(event);" onchange="search();" />
            <span>条/页</span>
        </div>
        <div class="default">@Html.Raw(ViewBag.PageContent)</div>
    </div>
    <!--/内容底部-->
</form>